"""
@File    : HW_object_oriented_programming_drive.py
@Author  : WorldWind(1772830365@qq.com)
@Time    : 2025/7/11
"""


class Car:
    def __init__(self, licensePlate, fuel):
        self.licensePlate = licensePlate
        self.fuel = fuel
        print('This is __init__ method. Car class startup')

    # 通过行驶距离distance 计算消耗油量 每公里消耗2L汽油
    def __drive(self, distance):
        # 返回消耗油量,如果计算消耗油量 > 剩余油量,则返回:The input driving distance is too large, and your remaining mileage is insufficient!
        # 如果输入destance < 0,则返回:The distance cannot be less than 0
        # 如果输入距离非法返回 Distance input error!
        # 根据创建对象后fuel值是判断对象是否合法
        if self.fuel <= 0:
            return 'The remaining oil quantity is incorrect!'
        return ((distance * 2
                 if distance * 2 <= self.fuel else 'The input driving distance is too large, and your remaining mileage is insufficient!')
                if distance > 0 else 'The distance cannot be less than 0')

    # 打印剩余的油量
    # 在此方法中调用drive方法,通过drive方法的返回值进行输出
    def checkFuel(self, distance):
        drive_result = self.__drive(distance)
        Remaining_oil_volume = drive_result if isinstance(drive_result, str) else (self.fuel - drive_result)
        self.fuel = 0 if isinstance(Remaining_oil_volume, str) else Remaining_oil_volume
        return f'The remaining oil volume is:{str(Remaining_oil_volume)}L' \
            if isinstance(Remaining_oil_volume, float) else Remaining_oil_volume

    def __del__(self):
        print('This is __del__ method. The Car class has been recycled')


try:
    fuel = float(input("Please enter the remaining oil quantity:"))
    distance = float(input("Please enter the driving distance:"))
    car = Car('湘A·8D9P9', fuel)
    print(car.checkFuel(distance))
except Exception as e:
    print(f'Have an error! : {str(e)}')
else:
    print('The end')
